import * as myThree from './lib/myThree/index'

const oMap = document.getElementsByClassName('map')[0]
const width = oMap.offsetWidth
const height = oMap.clientHeight

/* 场景 */
const scene = myThree.getScene()

/* 设置透视相机 */
const camera = myThree.createPerspectiveCamera(45, width / height, 1, 1000)
camera.position.set(10, 10, 10)
camera.lookAt(0, 0, 0)

const cubeCamera  = myThree.createCubeCamera()
console.log(camera)
scene.add( cubeCamera  );


myThree.openAxes(scene)
myThree.openGridHelper(scene, {
  size: 10,
  divisions: 10
})

const box = myThree.createBox()
box.position.set(0, 0, 0)
scene.add(box)

/* 渲染器 */
const renderer = myThree.createWebGLRenderer()

renderer.setSize(width, height)
oMap.append(renderer.domElement)
renderer.setClearColor('#000')

cubeCamera.position.copy(box.position)
cubeCamera.update( renderer, scene );
renderer.render(scene, camera)

// const O = [0, 0],
//   R = 10
// let a = 0,
//   x = O[0] + R * Math.cos(a),
//   z = O[1] + R * Math.sin(a)
// function animate() {
//   a = a + 0.01
//   x = O[0] + R * Math.cos(a)
//   z = O[1] + R * Math.sin(a)
//   camera.position.set(x, 5, z)
//   camera.lookAt(myThree.getVector3(0, 0, 0))
//   requestAnimationFrame(animate)
//   renderer.render(scene, camera)
// }
// animate()
